import 'package:flutter/material.dart';
import 'package:mobx/mobx.dart';
import "../util.dart";

part 'video_toolbar_state.g.dart';

// 影片页工具栏状态类
class VideoToolbarState = _VideoToolbarState with _$VideoToolbarState;
// 影片页工具栏图标按钮类
class IconbuttonState = _IconbuttonState with _$IconbuttonState;

// 影片页工具栏状态基类
abstract class _VideoToolbarState with Store {
  Color _defaultBtnColor = Colors.grey; // 默认按钮颜色

  Color _activeBtnColor = Colors.grey; // 活跃按钮颜色

  @observable
  IconbuttonState thumbBtn = IconbuttonState(); // 点赞按钮

  @observable
  IconbuttonState downthumbBtn = IconbuttonState(); // 点踩按钮

  @observable
  IconbuttonState coinBtn = IconbuttonState(); // 投币按钮

  @observable
  IconbuttonState recordBtn = IconbuttonState(); // 收藏按钮

  @observable
  IconbuttonState shareBtn = IconbuttonState(); // 分享按钮

  // 初始化状态，必须在初始化状态仓库时调用这个方法
  @action
  initState(Color activeColor, Color defaultColor, int thumbCount,
      int coinCount, int recordCount, int shareCount,
      {bool isRecordSelected, bool isThumbSelected}) {
    _activeBtnColor = activeColor;
    _defaultBtnColor = defaultColor;
    thumbBtn._initState(
        thumbCount, _defaultBtnColor, _defaultBtnColor, _activeBtnColor,
        selected: isThumbSelected);
    downthumbBtn._initState(
        0, _defaultBtnColor, _defaultBtnColor, _activeBtnColor);
    coinBtn._initState(
        coinCount, _defaultBtnColor, _defaultBtnColor, _activeBtnColor);
    recordBtn._initState(
        recordCount, _defaultBtnColor, _defaultBtnColor, _activeBtnColor,
        selected: isRecordSelected);
    shareBtn._initState(
        shareCount, _defaultBtnColor, _defaultBtnColor, _activeBtnColor);
    print('video_toolbar状态初始化已完成');
  }
}

// 影片页工具栏图标按钮基类
abstract class _IconbuttonState with Store {
  @observable
  int currCount = 0; // 当前计数

  @observable
  bool isSelected = false; // 是否选中

  @computed
  Color get currColor => isSelected ? _activeColor : _defaultColor; // 当前颜色

  @computed
  String get countText => formatVideoToolbarCount(currCount);

  Color _defaultColor = Colors.grey; // 默认颜色

  Color _activeColor = Colors.grey; // 活跃态颜色

  // 初始化按钮状态
  @action
  _initState(int count, Color color, Color defaultColor, Color activeColor,
      {bool selected = false}) {
    currCount = count;
    isSelected = selected;
    _activeColor = activeColor;
    print("按钮状态已初始化");
  }

  // 翻转按钮
  @action
  void toggle() {
    isSelected = !isSelected;
    currCount = isSelected ? currCount + 1 : currCount - 1;
  }

  // 设置按钮值
  @action
  setSelected(bool value) {
    isSelected = value;
  }
}
